package com.huirui.server.controller.admin;

import com.huirui.server.pojo.dto.ShortDatedProductDto;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.ShortDatedProductVo;
import com.huirui.server.service.ShortDatedProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController("adminShortDatedProductController")
@RequestMapping("/admin/short/dated/product")
@Slf4j
@Validated
@Tag(name = "临期商品管理", description = "小程序临期商品管理")
public class ShortDatedProductController {

    @Autowired
    private ShortDatedProductService shortDatedProductService;

    @PostMapping("/add/product")
    @Operation(summary = "新增临期特惠商品")
    public Result<Void> addShortDatedProduct(@RequestBody ShortDatedProductDto shortDatedProductDto) {
        shortDatedProductService.addShortDatedProduct(shortDatedProductDto);
        return Result.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查询临期特惠商品列表")
    public Result<PageResult<ShortDatedProductVo>> listShortDatedProduct(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "page") Long page,
            @RequestParam(value = "pageSize") Long pageSize
    ) {
        PageResult<ShortDatedProductVo> res = shortDatedProductService.listShortDatedProduct(keyword, page, pageSize);
        return Result.success(res);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除临期商品")
    public Result<Void> deleteShortDatedProduct(@RequestParam(value = "id") Long id) {
        shortDatedProductService.deleteShortDatedProduct(id);
        return Result.success();
    }

    @PutMapping("/update/product")
    @Operation(summary = "更新商品信息")
    public Result<Void> updateShortDatedProduct(@RequestBody ShortDatedProductDto shortDatedProductDto) {
        shortDatedProductService.updateShortDatedProduct(shortDatedProductDto);
        return Result.success();
    }
}
